/**
 * ajax调用方法
 * @param {Object} reqType 请求的类型（get，post）
 * @param {Object} reqURL 要请求的路径
 * @param {Object} reqPara 要传递的参数列表，如{ op: 1, key: 2 }
 * @return {Object} returndata 查询结果
 */
function callAJAX(reqType, reqURL, reqPara) {
	var returndata = '';
	$.ajax({
		type : reqType,
		url : reqURL,
		datatype : 'json',
		async : false, //不做异步刷新，解决执行顺讯问题
		data : reqPara,
		success : function(data) {
			returndata = data;
		},
		error : function() {
			returndata = '';
		}
	});
	return returndata;
}


/*新增弹框二级联动*/
function TwoLevel(selectId,form){
	/*品牌菜单*/
	var reqType = 'post';
	var reqURL = '../dropdown/getcollooge2';
	var reqPara = {};
	var stageData = callAJAX(reqType, reqURL, reqPara)
	if (stageData != '' && stageData != undefined) {
		if (stageData.code == 0) {
			$('#' + selectId).html(""); //获取id为selectId指定的控件内容
			var str = "<option value='0'>请选择</option>";
			for (var i = 0; i < stageData.resultObject.length; i++) {
				str += '<option value=' + stageData.resultObject[i].collegeid + '>' + stageData.resultObject[i].collegename + '</option>';
			}
			$('#' + selectId).append(str);
			form.render("select");
		} else {
			//layer.msg("未获取到阶段信息！");
			layer.msg('未获取到学院信息！', function() {});
		}
	} else {
		//layer.msg("阶段信息获取失败！");
		layer.msg('未获取到学院信息！', function() {});
	}

/*类型菜单*/
form.on('select(collegename)',function(data){
	$('.professionalname select').empty();//选择省的时候清空城市地区的值
	//$('.querytypename select').html('<option value="">城市</option>');
	$('.classname select').empty();
	$('.classname select').html('<option value="">请选择专业</option>');
	
	var collegename = data.value;
	var param = '?collegeid=' + collegename;
	
	var reqType = 'post';
	var reqURL = '../dropdown/getprofessional2' + param;
	var reqPara = {};
	var stageData = callAJAX(reqType, reqURL, reqPara)
	if (stageData != '' && stageData != undefined) {
		if (stageData.code == 0) {
			$('#' + 'professionalname').html(""); //获取id为selectId指定的控件内容
			var str = "<option value='0'>请选择专业</option>";
			for (var i = 0; i < stageData.resultObject.length; i++) {
				str += '<option value=' + stageData.resultObject[i].professionalid + '>' + stageData.resultObject[i].professionalname + '</option>';
			}
			$('#' + 'professionalname').append(str);
			form.render("select");
		} else {
			//layer.msg("未获取到阶段信息！");
			layer.msg('未获取到专业信息！', function() {});
		}
	} else {
		//layer.msg("阶段信息获取失败！");
		layer.msg('未获取到专业信息！', function() {});
	}
 });
}



/*新增弹框三级联动*/
function ThreeLevel(selectId,form){
	/*品牌菜单*/
	var reqType = 'post';
	var reqURL = '../dropdown/getcollooge2';
	var reqPara = {};
	var stageData = callAJAX(reqType, reqURL, reqPara)
	if (stageData != '' && stageData != undefined) {
		//alert(stageData.code)
		if (stageData.code == 0) {
			$('#' + selectId).html(""); //获取id为selectId指定的控件内容
			var str = "<option value='0'>请选择学院</option>";
			for (var i = 0; i < stageData.resultObject.length; i++) {
				str += '<option value=' + stageData.resultObject[i].collegeid + '>' + stageData.resultObject[i].collegename + '</option>';
			}
			$('#' + selectId).append(str);
			form.render("select");
		} else {
			
			layer.msg('未获取到学院信息！', function() {});
		}
	} else {
		
		layer.msg('未获取到学院信息！', function() {});
	}

/*类型菜单*/
form.on('select(collegename)',function(data){
	$('.professionalname select').empty();//选择省的时候清空城市地区的值
	//$('.querytypename select').html('<option value="">城市</option>');
	$('.classname select').empty();
	$('.classname select').html('<option value="">请选择专业</option>');
	
	var collegename = data.value;
	var param = '?collegeid=' + collegename;
	
	var reqType = 'post';
	var reqURL = '../dropdown/getprofessional2' + param;
	var reqPara = {};
	var stageData = callAJAX(reqType, reqURL, reqPara)
	if (stageData != '' && stageData != undefined) {
		if (stageData.code == 0) {
			$('#' + 'professionalname').html(""); //获取id为selectId指定的控件内容
			var str = "<option value='0'>请选择专业</option>";
			for (var i = 0; i < stageData.resultObject.length; i++) {
				str += '<option value=' + stageData.resultObject[i].professionalid + '>' + stageData.resultObject[i].professionalname + '</option>';
			}
			$('#' + 'professionalname').append(str);
			form.render("select");
		} else {
			//layer.msg("未获取到阶段信息！");
			layer.msg('未获取到专业信息！', function() {});
		}
	} else {
		//layer.msg("阶段信息获取失败！");
		layer.msg('未获取到专业信息！', function() {});
	}
});

/*配置菜单*/
form.on('select(professionalname)',function(data){
	$('.classname select').empty();//选择市的时候清空区的值
	$('.classname select').html('<option value="0">请选择班级</option>');
	var professionalname = data.value;
	var param2 = '?professionalid=' + professionalname;
	//alert(param2);

	var reqType = 'post';
	var reqURL = '../dropdown/getclass2' + param2;
	var reqPara = {};
	var stageData = callAJAX(reqType, reqURL, reqPara)
	if (stageData != '' && stageData != undefined) {
		if (stageData.code == 0) {
			$('#' + 'classname').html(""); //获取id为selectId指定的控件内容
			var str = "<option value='0'>请选择班级</option>";
			for (var i = 0; i < stageData.resultObject.length; i++) {
				str += '<option value=' + stageData.resultObject[i].classid + '>' + stageData.resultObject[i].classname + '</option>';
			}
			//alert(str);
			$('#' + 'classname').append(str);
			form.render("select");
		} else {
			//layer.msg("未获取到阶段信息！");
			layer.msg('未获取到班级信息！', function() {});
		}
	} else {
		//layer.msg("阶段信息获取失败！");
		layer.msg('未获取到班级信息！', function() {});
	}
});
}



